# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libmng

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.0.2
pkgrel=1
pkgdesc="Simple, small, C++ XML parser that can be easily integrated into other programs (mingw-w64)"
arch=('any')
url="http://sourceforge.net/projects/libmng"
license=("zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-libjpeg-turbo" "${MINGW_PACKAGE_PREFIX}-lcms2" "${MINGW_PACKAGE_PREFIX}-zlib")
options=('strip' 'staticlibs')
source=("http://downloads.sourceforge.net/libmng/${_realname}-${pkgver}.tar.xz"{,.asc}
    libmng-1.0.10-mingw.patch
    libmng-1.0.9-dont-leak-zlib-streams.diff
    no-undefined.patch)
md5sums=('3804bf2523af9b4e0670b5982b3bf984'
         'SKIP'
         'cb375eee738835855615afd5c056252e'
         '9a3638775d5efaa1111973b40f4f96a4'
         'e4614f8cd3c813b38340468b2277c3ae')

prepare() {
  cd "$srcdir/${_realname}-${pkgver}"
  patch -p0 -i "$srcdir"/libmng-1.0.9-dont-leak-zlib-streams.diff
  patch -p1 -i "$srcdir"/libmng-1.0.10-mingw.patch
  patch -p1 -i "$srcdir"/no-undefined.patch
}

build() {
    mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd ${srcdir}/${_realname}-${pkgver}
  make distclean
    cd "${srcdir}/build-${MINGW_CHOST}"
  "${srcdir}"/${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --with-lcms2
    make
}

package() {
    cd "${srcdir}/build-${MINGW_CHOST}"
    make DESTDIR="$pkgdir" install
    find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
    rm -r "${pkgdir}${MINGW_PREFIX}/share"
}
